/**
 * @file   PA_D.cpp
 * @author ZL <zuoling@Black>
 * @date   Fri Oct  7 01:11:14 2022
 * 
 * @brief  1.8.2 PA_D
 * 
 * 
 */

#include "EquationSolver.h"
/** 
 * 
 * 
 * 
 * @return Create three function classes in problem D
 */
class F1 : public Function
{
public:
    double operator ()(double _x)
	{
	    double x = _x;
	    double y;
	    y = sin(x/2)-1;
	    return y;
	};
};

class F2 : public Function
{
public:
    double operator ()(double _x)
	{
	    double x = _x;
	    double y;
	    y = exp(x)-tan(x);
	    return y;
	};
};

class F3 : public Function
{
public:
    double operator ()(double _x)
	{
	    double x = _x;
	    double y;
	    y = pow(x,3)-12*pow(x,2)+3*x+1;
	    return y;
	};
};

int main(int argc, char* argv[])
{
    F1 f1;
    F2 f2;
    F3 f3;
    Secant s1(0, pi/2, eps, 20, f1);
    Secant s2(1, 1.4, eps, 20, f2);
    Secant s3(0, -0.5, eps, 20, f3);
    double y1 = s1.solve();
    double y2 = s2.solve();
    double y3 = s3.solve();

    std::cout << "when x_0 = 0, x_1 = pi/2, function1'root is r1 = " << y1 <<", f(r) = "<< (f1)(y1)<<std::endl;
    std::cout << "when x_0 = 1, x_1 = 1.4, function1'root is r2 = " << y2 <<", f(r) = "<< (f2)(y2)<<std::endl;
    std::cout << "when x_0 = 0, x_1 = -0.5, function1'root is r3 = " << y3 <<", f(r) = "<< (f3)(y3)<<std::endl;
    return 0;
};
